package org.example.leetcode.common.exception;

import org.example.leetcode.common.pojo.GlobalResponse;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * GlobalException
 *
 * @author admin
 * @version 2023/11/28 17:56
 **/
@Component
@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(MyException.class)
    public GlobalResponse exceptionHandle(MyException e){
        e.printStackTrace();
        return GlobalResponse.fail(e.getMessage());
    }
    @ExceptionHandler(UnAuthorizationException.class)
    public GlobalResponse exceptionHandle(UnAuthorizationException e){
        e.printStackTrace();
        return GlobalResponse.fail(HttpStatus.UNAUTHORIZED.value()+"",e.getMessage());
    }
    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    public GlobalResponse exceptionHandle(HttpRequestMethodNotSupportedException e)
    {
        e.printStackTrace();
        return GlobalResponse.fail("换个姿势试试");
    }
    @ExceptionHandler(Exception.class)
    public GlobalResponse exceptionHandle(Exception e)
    {
        e.printStackTrace();
        return GlobalResponse.fail("服务器开小差");
    }
}
